﻿/// Copyright (c) Microsoft Corporation.  All rights reserved.
using System;
using System.Collections.Generic;

namespace Tcvt.Packages
{
    internal class BuildAgentComparer : IComparer<BuildAgent>
    {
        public int Compare(BuildAgent buildAgent1, BuildAgent buildAgent2)
        {
            int queueCount1 = buildAgent1.TfsBuildAgent.QueueCount;
            int queueCount2 = buildAgent2.TfsBuildAgent.QueueCount;

            if (queueCount1 < queueCount2)
                return -1;
            else if (queueCount2 < queueCount1)
                return 1;
            else // they're equal; next criteria is the weight factor.
            {
                int weightFactor1 = buildAgent1.Weight;
                int weightFactor2 = buildAgent2.Weight;

                // The greater the weight, the higher the sort order
                if (weightFactor1 > weightFactor2)
                    return -1;
                else if (weightFactor2 > weightFactor1)
                    return 1;
                return 0; // equal weights... pick whichever one.
            }
        }
    }
}
